package level.editor.menu;

import level.editor.command.Command;
import level.editor.command.RequiresModule;
import level.editor.command.RequiresUpdate;
import level.editor.mediator.Module;
import level.editor.state.StateModule;
import level.state.StateWriter;

/*
 * Command implementation of save function.
 */

public class StateSaveCommand extends Command implements RequiresUpdate,
		RequiresModule
{
	public StateSaveCommand()
	{
		super("StateModule");
	}

	@Override
	public void execute(Module m)
	{
		StateModule module = (StateModule) m;
		if (module.isModified())
		{
			if (module.getState().getFile() != null)
			{
				StateWriter.write(module.getState());
				module.setModified(false);
			}
			else if (module.getState().getFile() == null)
				module.pushDownCommand(new StateSaveAsCommand());
		}
	}
}
